<extend name="Home@Base/common" xmlns="http://www.w3.org/1999/html"/>
<block name="body">
    <div class="span9 page_message">
        <section id="contents"> <include file="Home@Addons/_nav" />
            <div class="tab-content">
                <php> $post_url || $post_url = U('add?model='.$model['id'], $get_param);</php>
                <form class="form-horizontal form-center" method="post" action="{$post_url}" id="form">
                    <input type="hidden" name='pid' value='{$pid}'  />
                    <input type="hidden" name='noticeId' value='{$noticeId}' />
                    <input type="hidden" name='receiver' value='{$receiver}' />
                    <div>
                        <input class="button1" type="button" onclick="javascript:window.history.back()" value="返回"/>
                        <label class="item-label">要回复的任务标题：{$title}</label>
                    </div>
                    <hr>
                    <div class="form-item cf">
                        <label class="item-label"> <span class="need_flag">*</span>回复内容<span class="check-tips"></span></label>
                        <label class="textarea input-large">
                            <textarea class="text input-large" name="comment" >{$data.comment}</textarea>
                        </label>
                    </div>

                    <input type="hidden" id="filesIds" name='fileids' value='{$data.fileids}' />
                    <div class="form-item cf">
                        <label class="item-label"><span class="need_flag">*</span>文件上传<span class="check-tips">支持文件格式doc,docx,ppt,pptx,xls,xlsx</span></label>
                        <div class="controls upload_file">
                            <div id="upload_file_files" class="uploadrow_file" ></div>
                            <input type="hidden" name="files" value=""/>
                            <div class="upload-img-box" id="files_box"></div>
                        </div>
                    </div>
                    <div class="form-item form_bh">
                        <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">回 复</button>
                    </div>
                </form>
            </div>
        </section>
    </div>
</block>
<block name="style">
    <style type="text/css">
        .button1 {
            background-color: #008CBA; /* blue */
            border: none;
            color: white;
            padding: 5px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 14px;
        }
    </style>
</block>
<block name="script">
    <link href="__STATIC__/emoji.css" rel="stylesheet">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript">
        var filesInfo = [];
        var fileUploader = null;
        var fileObjs = [];

        $(function(){
            showTab();

            fileUploader = initUploadFileWithRemove(fileUploadSuccess)[0];
            init_file_uplaod();
        });

        // upload files
        //上传附件组件
        function init_file_uplaod () {
            var tmp = $('#filesIds').val();
            if (tmp != ''){
                filesInfo = JSON.parse(tmp);
            }

            var box_html = "<div class=\"upload-pre-file\">";
            console.log(filesInfo.length);
            for (let i = 0; i < filesInfo.length; i++) {
                console.log(filesInfo[i]);
                box_html += "<span class=\"upload_icon_all\"></span>" + filesInfo[i].name;
                box_html += "<span class=\"emoji emoji274c\" onclick=\"delFile(" + i +")\"></span>";
            }
            box_html += "</div>"
            document.getElementById('files_box').innerHTML = box_html;
        }
        function fileUploadSuccess(file,data, name){
            if(data.status){
                filesInfo.push({
                    id: data.id,
                    name: data.name
                })
                fileObjs.push(file)
                var tmp = JSON.stringify(filesInfo);
                $('#filesIds').val(tmp);

                var box_html = "<div class=\"upload-pre-file\">";
                console.log(filesInfo);
                for (let i = 0; i < filesInfo.length; i++) {
                    box_html += "<span class=\"upload_icon_all\"></span>" + filesInfo[i].name;
                    box_html += "<span class=\"emoji emoji274c\" onclick=\"delFile(" + i + ")\"></span>";
                }
                box_html += "</div>"

                $("input[name="+name+"]").parent().find('.upload-img-box').html(box_html);
            }
        }
        function delFile (index) {
            console.log('delFile');
            fileUploader.removeFile(fileObjs[index]);
            fileObjs.splice(index,1);
            filesInfo.splice(index,1);
            var tmp = JSON.stringify(filesInfo);
            $('#filesIds').val(tmp);
            document.getElementById('files_box').innerHTML = '';
            var box_html = "<div class=\"upload-pre-file\">";
            console.log(filesInfo.length);
            for (let i = 0; i < filesInfo.length; i++) {
                console.log(filesInfo[i]);
                box_html += "<span class=\"upload_icon_all\"></span>" + filesInfo[i].name;
                box_html += "<span class=\"emoji emoji274c\" onclick=\"delFile(" + i +")\"></span>";
            }
            box_html += "</div>"
            console.log(box_html);
            document.getElementById('files_box').innerHTML = box_html;
        }
    </script>
</block>